package com.sskj.login.presenter;

import com.sskj.common.base.HttpData;
import com.sskj.lib.http.CallBackOption;
import com.sskj.login.bean.LoginBean;
import com.sskj.login.ui.activity.LoginActivity;


public class LoginActivityPresenter extends BasePresenter<LoginActivity> {

    public void login(String areaCode, String account, String pwd, String type) {

        httpService.login(areaCode, account, pwd, type)
                .execute(new CallBackOption<HttpData<LoginBean>>() {}
                                .loadBind(mView)
                                .execute(httpData -> {
                                    if (httpData.getData().getIsGoogleAuthentication() == 0) {
                                        mView.loginSuccess(httpData.getData());
                                    } else {
                                        mView.googleCheck(httpData.getData());
                                    }
                                })
                );
    }


    public void checkGoogle(String code, LoginBean loginBean) {
        httpService.checkGoogle(code, loginBean.getId())
                .execute(new CallBackOption<HttpData>() {}
                        .loadBind(mView)
                        .execute(httpData -> {
                            mView.checkSuccess(loginBean);
                        }));
    }


    /**
     * 登录成功，发送登录短信
     *
     * @param account
     */
    public void sendLoginSms(String account, String id, String token) {

        httpService.sendLoginSms(account, id, token)
                .execute(new CallBackOption<HttpData>() {
                }
                        .loadBind(mView)
                        .execute(httpData -> {

                        }));
    }
}
